package com.movie.demo.controller;

import com.movie.demo.pojo.Seat;
import com.movie.demo.Utlis.result.CommonResult;
import com.movie.demo.pojo.vo.SeatInfo;
import com.movie.demo.service.SeatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
public class SeatController {
    @Autowired
    private SeatService seatService;

    @PostMapping("/allSeat")
    public CommonResult<List> allSeat(){
        List<Seat> seatList=seatService.allSeat();
        return CommonResult.success(seatList);
    }
    @RequestMapping("/SelectSeat")
    public CommonResult<List> selectSeat(@RequestBody Seat seat){
        List<Seat> seatList=seatService.selectSeat(seat.getMid(),seat.getRoom_id(),seat.getSession_id(),seat.getCinema_id());
        return CommonResult.success(seatList);
    }
    @PostMapping("/addSeat")
    public CommonResult addScreen(@RequestBody Seat seat){
        boolean flag=seatService.addSeat(seat);
        if(flag){
            return CommonResult.success(seat.getId());
        }
        return CommonResult.failed();
    }
    @PostMapping("/updataSeatState")
        public CommonResult updataSeatState(@RequestBody Seat seat){
        boolean flag=seatService.updateSeatState(seat.getId(),seat.getFlag());
        if (flag){
            return CommonResult.success(flag);
        }
        return CommonResult.failed();
    }
    @PostMapping("/deleteSeat")
    public CommonResult deleteSeat(@RequestBody Seat seat){
        boolean flag=seatService.DeleteSeat(seat.getId());
        if(flag){
            return CommonResult.success(flag);
        }
        return CommonResult.failed();
    }

    @PostMapping("/selectSeatInfo")
    public CommonResult<List> selectSeatInfo(){
        List<SeatInfo> seatInfo=seatService.selectSeatInfo();
        return CommonResult.success(seatInfo);

    }
    @PostMapping("/selectSeatInfoOne")
    public CommonResult<Boolean> selectSeatInfoOne(@RequestBody Seat seat){
        boolean seatInfo=seatService.selectSeatInfoOne(seat.getMid(),seat.getSession_id(),seat.getRoom_id(),seat.getCinema_id(),seat.getSeat(),seat.getUid());
        return CommonResult.success(seatInfo);

    }
}
